package br.org.etec.dotcao.model;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class RepositoryFactory {
	
	private static final Map<Class<?>, Repository<?>> repositories = Collections.synchronizedMap(new HashMap<Class<?>, Repository<?>>());
	
	static{
		repositories.put(User.class, new UserRepositoryImpl());
		repositories.put(State.class, new StateRepositoryImpl());
		repositories.put(Race.class, new RaceRepositoryImpl());
		repositories.put(City.class, new CityRepositoryImpl());
		repositories.put(News.class, new NewsRepositoryImpl());
		repositories.put(Animal.class, new AnimalRepositoryImpl());
	}
	
	@SuppressWarnings("unchecked")
	public static <T> Repository<T> get(Class<T> type){
		Repository<T> result = (Repository<T>) repositories.get(type);
		
		if(result != null){
			return result;
		}
		
		return new RepositoryImpl<T>(type);
	}

}
